<?php
namespace app\api\model;


use app\model\Base;

class EverydayPerformance extends Base
{
    public static function createRecord($user_id, $order)
    {
        if ($parent_ids = User::where('id', $user_id)->value('parent_ids')){
//            $str = str_replace('|', ',', substr_replace(substr_replace($parent_ids, '', 0, 1), '', -1, 1));
            self::createOrder($order, $parent_ids);
        }
        return true;
    }

    public static function createOrder($order, $parent_ids)
    {
        return self::create([
            'orders_id'=>$order['id'],
            'user_ids'=>$parent_ids,
            'pay_money'=>$order['total_amount'],
            'pay_user_id'=>$order['user_id'],
        ]);
    }

    public function getAmountAttr($value, $data)
    {
        $val = $data['pay_money'];
        return $val;
    }

    public function getAmountFormatAttr($value, $data)
    {
        return bcdiv($data['pay_money'], Base::$hundred, 2);
    }

    public function getTypeFormatAttr($value, $data)
    {
        $str = "新增订单";
        if($data['type'] == 1){
            $str = "复投订单";
        }
        return $str;
    }

    public function getContentAttr($value, $data)
    {
        return "所属订单：" . $data['benefit_order_id'];
    }

//    public function getPayTypeFormatAttr($value, $data)
//    {
//        $str = "";
//        switch (($data['orderitem'])['pay_type']){
//            case 'money':
//                $str = "余额付款";
//                break;
//            case 'wxpay':
//                $str = "微信付款";
//                break;
//            case 'alipay':
//                $str = "支付宝付款";
//                break;
//            case 'gold':
//                $str = "消费积分付款";
//                break;
//            case 'goumai_money':
//                $str = "民尚积分付款";
//                break;
//        }
//        return $str;
//    }



//    public function orderItem()
//    {
//        return $this->hasOne(BenefitOrder::class, 'id', 'benefit_order_id');
//    }
}